//
//  ViewController.m
//  06_UINavigationController
//
//  Created by dllo on 16/7/21.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "ViewController.h"
#import "SecViewController.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    // navgationBar 横屏 32 竖屏44
    // 设置navgationBar的属性
    // 1. 标题
    self.title = @"难受";
    self.navigationItem.title = @"真难受";
    // 2. 标题视图 (修改x y对视图本身大小没有影响)
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"难受", @"难受的要死"]];
    segment.frame = CGRectMake(0, 0, 150, 44);
    self.navigationItem.titleView = segment;
    // 3. 设置navgation左按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"难受" style:UIBarButtonItemStylePlain target:self action:@selector(back:)];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)];
    
    // 4.
    UIBarButtonItem *barButton1 = [[UIBarButtonItem alloc] initWithTitle:@"难受" style:UIBarButtonItemStylePlain target:self action:@selector(back:)];
    UIBarButtonItem *barButton2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)];
    self.navigationItem.leftBarButtonItems = @[barButton1, barButton2];
    
    // 5. bar的隐藏
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.hidden = NO;
    // 6. barStyle
    self.navigationController.navigationBar.barStyle = 0;
    // 7. 背景颜色
    // self.navigationController.navigationBar.backgroundColor = [UIColor cyanColor];
    self.navigationController.navigationBar.barTintColor = [UIColor cyanColor];
    // 8. 导航栏元素的颜色
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    // 9. 设置为半透明
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor blackColor];
    button.frame = CGRectMake(0, 0, 200, 200);
    [button setTitle:@"难受死我了" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    // 10. 当设置非半透明时 button的坐标向下平移64
    self.navigationController.navigationBar.translucent = NO;
    // self.edgesForExtendedLayout = UIRectEdgeNone; // 与translucent为no时的效果一样
    
    // 功能相同的部分用push pop跳转页面
    // 功能不同的部分用模态跳转页面
    
    // 页面跳转
    // 1. push 如栈
    // 2. pop 出栈
    //
    // 3. self.navigationController.viewControllers
    // 4. topViewController 栈顶视图控制器
    // 5. visibleViewController
    
    
}
// 页面跳转
- (void)click:(UIButton *)button {
    // 将视图控制器入栈
    SecViewController *sec = [[SecViewController alloc] init];
    [self.navigationController pushViewController:sec animated:YES];
    NSLog(@"%@", self.navigationController.viewControllers);

}

- (void)back:(UIBarButtonItem *)button {
    NSLog(@"返回");
}

- (void)add:(UIBarButtonItem *)button {
    NSLog(@"add");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
